/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package eao;

import entidades.Cliente;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import facades.AbstractFacade;
import java.util.List;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
import javax.persistence.PersistenceException;

/**
 *
 * @author alberto
 */
@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
public class ClientesEAO extends AbstractFacade<Cliente> implements ClientesEAOLocal {
    @PersistenceContext(unitName = "TP-PW-ejbPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }
    public ClientesEAO() {
        super(Cliente.class);
    }
    
    @Override
    public List listarClientes() {
        List lista = null;
        lista = em.createNamedQuery("Cliente.findAll").getResultList();       
        return lista;
    }
    
    @Override
    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public void create(Cliente cliente) 
    {
        try
        {
            em.persist(cliente);
            em.flush();
            cliente = em.merge(cliente);
        }
        catch (PersistenceException e)
        {
             new Exception(e.getMessage());
        }
        
    }
}
